/* GLScene.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <graphics/GLScene.h>
#include <GL/glu.h>
#include <GL/gl.h>

GLScene::GLScene() :
	perspectiveChange(false), glCamera(NULL)
{

}
GLScene&
GLScene::setFOVy(double fovy)
{
	if (fovy > 0 && fovy < 180)
		this->fovy = fovy;
	perspectiveChange = true;
	return *this;
}

GLScene&
GLScene::setAspectRatio(double ratio)
{
	this->aspectRatio = ratio;
	perspectiveChange = true;

	return *this;
}

GLScene&
GLScene::setZNear(double zNear)
{
	this->zNear = zNear;
	perspectiveChange = true;

	return *this;
}

GLScene&
GLScene::setZFar(double zFar)
{
	this->zFar = zFar;
	perspectiveChange = true;

	return *this;
}

GLScene&
GLScene::setPerspective(double fovy, double aspectRatio, double zNear,
	double zFar)
{
	if (fovy > 0 && fovy < 180)
		this->fovy = fovy;
	this->aspectRatio = aspectRatio;

	this->zNear = zNear;
	this->zFar = zFar;
	perspectiveChange = true;

	return *this;
}

void
GLScene::updatePerspective()
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(fovy, aspectRatio, zNear, zFar);
	perspectiveChange = false;
}

void
GLScene::updateCamera()
{
	if (glCamera != NULL)
		glCamera->updateCamera();
}

